<?php

namespace App\Models;

use houdunwang\arr\Arr;
use Illuminate\Database\Eloquent\Model;

class Catergory extends Model
{
    protected $fillable=['title','icon','parent_id'];

    public function getAllCategory(){
        $categories = Arr::category(self::get());
//        dd($categories->toArray());
        foreach ($categories as $k => $v){
            $v['is_parent'] = $v['id'] == $this['parent_id'];
            $v['is_child'] = Arr::isChild($categories,$v['id'],$this['id'],'id','parent_id');
            $categories[$k]=$v;
        }
        return $categories;
    }

    public function fatherName(){
        return $this->belongsTo(Catergory::class,'parent_id','id');
    }
}
